package org.example.ttms.controller;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import org.example.ttms.customize.Detail;
import org.example.ttms.entityClass.ticket.Ticket;

import java.util.List;

public class TicketTableViewController {

    @FXML
    private TableView<Ticket> tableView;

    @FXML
    private TableColumn<Ticket, String> ticketIdTableColumn;

    @FXML
    private TableColumn<Ticket, String> seatIdTableColumn;

    @FXML
    private TableColumn<Ticket, String> ticketTypeTableColumn;

    @FXML
    private TableColumn<Ticket, Double> priceTableColumn;

    @FXML
    private TableColumn<Ticket, String> statusTableColumn;

    @FXML
    private TableColumn<Ticket, String> departureTableColumn;

    @FXML
    private TableColumn<Ticket, String> destinationTableColumn;

    @FXML
    private TableColumn<Ticket, String> goTimeTableColumn;

    @FXML
    private TableColumn<Ticket, String> arrivalTimeTableColumn;

    @FXML
    private TableColumn<Ticket, String> buyerNameTableColumn;

    public void initialize(){
        Ticket ticket = new Ticket();
        List<Ticket> ticketList = ticket.obtainTripsAllTicket(Detail.trips);
        //tableView
        ticketIdTableColumn.setCellValueFactory(cellData -> cellData.getValue().ticketIdProperty());
        seatIdTableColumn.setCellValueFactory(cellData -> cellData.getValue().seatIdProperty());
        ticketTypeTableColumn.setCellValueFactory(cellData -> cellData.getValue().typeProperty());
        priceTableColumn.setCellValueFactory(cellData -> cellData.getValue().priceProperty().asObject());
        statusTableColumn.setCellValueFactory(cellData -> cellData.getValue().statusProperty());
        departureTableColumn.setCellValueFactory(cellData -> cellData.getValue().departureProperty());
        destinationTableColumn.setCellValueFactory(cellData -> cellData.getValue().destinationProperty());
        goTimeTableColumn.setCellValueFactory(cellData -> cellData.getValue().goTimeProperty());
        arrivalTimeTableColumn.setCellValueFactory(cellData -> cellData.getValue().arrivalTimeProperty());
        buyerNameTableColumn.setCellValueFactory(cellData -> cellData.getValue().buyerNameProperty());
        ObservableList<Ticket> observableList = FXCollections.observableArrayList(ticketList);
        tableView.setItems(observableList);
    }

}

